package com.ht.api.db.hlink.function.impl;

import cn.hutool.json.JSONUtil;
import com.ht.api.db.Db;
import com.ht.api.db.Entity;
import com.ht.api.db.hlink.function.HlinkFunction;
import lombok.extern.slf4j.Slf4j;

import javax.sql.DataSource;

@Slf4j
public class EventFormatFunction implements HlinkFunction<String> {

	@Override
	public String format(DataSource ds, Object value, Entity entity) {
		String eventType = entity.getStr("event_type");
		String eventKey = entity.getStr("event_key");
		String relationId = entity.getStr("relation_id");
		int relationType = entity.getInt("relation_type");

		String relationName = "";
		if (relationType == 1) {
			String sql = "select ad_name from creative c left join ad a on c.ad_id = a.main_id where c.main_id = ?";

			relationName = Db.val(ds, sql, String.class, relationId);
		}

		String msg = "";
		if (eventType.equals("moment")) {
			switch (eventKey) {
				case "show":
					msg = "曝光朋友圈：" + relationName;
					break;
				case "like":
					msg = "点赞朋友圈：" + relationName;
					break;
				case "comment":
					msg = "评论朋友圈：" + relationName;
					break;
			}
		}

		return msg;
	}

}
